package net.maku.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
import net.maku.project.convert.StepDetailConvert;
import net.maku.project.dao.StepDetaiDao;
import net.maku.project.entity.StepDetailEntity;
import net.maku.project.query.StepDetailQuery;
import net.maku.project.service.StepDetailService;
import net.maku.project.vo.StepDetailVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @FileName: StepDetailServiceImpl
 * @Project: maku-boot-zzhl
 * @Package: net.maku.project.service
 * @Author: Aili
 * @Date: 2024/7/23 1:33
 * @Version: 1.0.0
 * @Description: StepDetailServiceImpl Description
 */
@Service
public class StepDetailServiceImpl extends BaseServiceImpl<StepDetaiDao,StepDetailEntity> implements StepDetailService {

    @Autowired
    private StepDetaiDao stepDetaiDao;

    @Override
    public PageResult<StepDetailVO> page(StepDetailQuery query) {
        IPage<StepDetailEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
        return new PageResult<>(StepDetailConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }

    private LambdaQueryWrapper<StepDetailEntity> getWrapper(StepDetailQuery query) {
        LambdaQueryWrapper<StepDetailEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Objects.nonNull(query.getProjectId()), StepDetailEntity::getProjectId, query.getProjectId())
               .eq(Objects.nonNull(query.getStepId()), StepDetailEntity::getStepId, query.getStepId())
                .orderByDesc(StepDetailEntity::getCreateTime);
        return wrapper;
    }



    @Override
    public int insert(StepDetailEntity record) {
        return stepDetaiDao.insert(record);
    }

    /**
     * @param entity
     * @return
     */
    @Override
    public boolean save(StepDetailEntity entity) {
        return StepDetailService.super.save(entity);
    }


}
